home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / JAVA / UTIL / Random.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  1.2 KB  |  70 lines

  1. package java.util;
  2.  
  3. public class Random {
  4.    private long seed;
  5.    private static final long multiplier = 25214903917L;
  6.    private static final long addend = 11L;
  7.    private static final long mask = (1L << 48) - 1L;
  8.    private double nextNextGaussian;
  9.    private boolean haveNextNextGaussian;
  10.  
  11.    public Random() {
  12.       this(System.currentTimeMillis());
  13.    }
  14.  
  15.    public Random(long var1) {
  16.       this.haveNextNextGaussian = false;
  17.       this.setSeed(var1);
  18.       this.haveNextNextGaussian = false;
  19.    }
  20.  
  21.    public synchronized void setSeed(long var1) {
  22.       this.seed = (var1 ^ 25214903917L) & mask;
  23.    }
  24.  
  25.    private synchronized int next(int var1) {
  26.       long var2 = this.seed * 25214903917L + 11L & mask;
  27.       this.seed = var2;
  28.       return (int)(var2 >>> 48 - var1);
  29.    }
  30.  
  31.    public int nextInt() {
  32.       return this.next(32);
  33.    }
  34.  
  35.    public long nextLong() {
  36.       return ((long)this.next(32) << 32) + (long)this.next(32);
  37.    }
  38.  
  39.    public float nextFloat() {
  40.       int var1 = this.next(30);
  41.       return (float)var1 / 1.0737418E9F;
  42.    }
  43.  
  44.    public double nextDouble() {
  45.       long var1 = ((long)this.next(27) << 27) + (long)this.next(27);
  46.       return (double)var1 / (double)(1L << 54);
  47.    }
  48.  
  49.    public synchronized double nextGaussian() {
  50.       if (this.haveNextNextGaussian) {
  51.          this.haveNextNextGaussian = false;
  52.          return this.nextNextGaussian;
  53.       } else {
  54.          double var1;
  55.          double var3;
  56.          double var5;
  57.          do {
  58.             var1 = (double)2.0F * this.nextDouble() - (double)1.0F;
  59.             var3 = (double)2.0F * this.nextDouble() - (double)1.0F;
  60.             var5 = var1 * var1 + var3 * var3;
  61.          } while(var5 >= (double)1.0F);
  62.  
  63.          double var7 = Math.sqrt((double)-2.0F * Math.log(var5) / var5);
  64.          this.nextNextGaussian = var3 * var7;
  65.          this.haveNextNextGaussian = true;
  66.          return var1 * var7;
  67.       }
  68.    }
  69. }
  70.